import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class Airplane {
	/*
	private static String help = "Usage:\nAirplane -(denv | dlan) filename\n\nInfo:\ndenv: Define enviroment, filename points to the evniroment definition file.\ndlan: Define airplane simulation, filename points to previously created airplane enviroment.";
	private static String message = "Error message: Wrong parameters\nFor help provide -h as parameter";

	public static void main(String[] args) {
		if (args.length == 1) {
			if (args[0].equals("-h")) {
				System.out.println(help);
			} else {
				System.err.println(message);
			}

			return;
		}

		if (args.length != 2) {
			System.err.println(message);
			return;
		}

		try {
			String code = "";
			String codeLine = "";
			BufferedReader fileReader = new BufferedReader(new FileReader(
					args[1]));

			while (null != (codeLine = fileReader.readLine())) {
				if (!codeLine.equals("")) {
					code += codeLine.replaceAll("\\s+", " ").trim() + "\n";
				}
			}

			BufferedWriter fileWriter = new BufferedWriter(new FileWriter(
					"refinedCode.denv"));
			fileWriter.write(code);
			fileWriter.close();

			/** Tokenize **/
			
			/*
			if (args[0].equals("denv")) {
				// define environment

				String okolina = "okolina\\s*\\(\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s*\\)\\s*";
				String oblaci = "oblaci\\s+pocetok\\s+(\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s*:\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*)*\\s+kraj\\s*";
				String pateki = "pateki\\s+pocetok\\s+([1-9][0-9]*\\s*[xXvV]\\s*-\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s+)*kraj\\s*";
				String pisti = "pisti\\s+(\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s*,)*\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s*";
				String avion = "avion\\s+[iIsSzZjJ]\\s*\\(\\s*[1-9][0-9]*\\s*-\\s*[1-9][0-9]*\\s*\\)\\s*";
				String codeRegExp = okolina + "(" + oblaci + "\\s+)?" + "(" + pateki + "\\s+)?" + "(" + pisti + "\\s+)?" + avion;
				
				if(code.matches(codeRegExp)){
					System.out.println("Tokenizing...");
				}else{
					System.err.println("Syntax error!");
					return;
				}
				
				System.out.println("Creating syntax tree and tokenizing denv");
				return;
			}

			if (args[0].equals("dlan")) {
				// define simulation
				System.out.println("Creating syntax tree and tokenizing dlan");
				return;
			}

		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

		System.out.println(message);
	}
	*/
}
